﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Configuration;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;


public partial class admin_doc : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        BindGridviewData();

       // Response.Write(Session["p_id"]);
    }
    // Bind Gridview Data
    private void BindGridviewData()
    {
        SqlConnection con = null;
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);

        con.Open();
        SqlCommand cmd = new SqlCommand("select * from files where id='"+ Session["p_id"] +"'", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);

        gvDetails.DataSource = ds;
        gvDetails.DataBind();

        con.Close();
    }
    protected void lnkDownload_Click(object sender, EventArgs e)
    {
        LinkButton lnkbtn = sender as LinkButton;
        GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
        string file_path = gvDetails.DataKeys[gvrow.RowIndex].Value.ToString();
        Response.ContentType = "image/jpg";
        Response.AddHeader("Content-Disposition", "attachment;filename=\"" + file_path + "\"");
        Response.TransmitFile(Server.MapPath(file_path));
        Response.End();
    }



    protected void Button1_Click(object sender, System.EventArgs e)
    {
        //if (FileUpload1.HasFile)
        //{

        //    string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);

        //    string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);

        //    string documentType = string.Empty;



        //    //provide document type based on it's extension

        //    switch (fileExtension)
        //    {

        //        case ".pdf":

        //            documentType = "application/pdf";

        //            break;

        //        case ".xls":

        //            documentType = "application/vnd.ms-excel";

        //            break;

        //        case ".xlsx":

        //            documentType = "application/vnd.ms-excel";

        //            break;

        //        case ".doc":

        //            documentType = "application/vnd.ms-word";

        //            break;

        //        case ".docx":

        //            documentType = "application/vnd.ms-word";

        //            break;

        //        case ".gif":

        //            documentType = "image/gif";

        //            break;

        //        case ".png":

        //            documentType = "image/png";

        //            break;

        //        case ".jpg":

        //            documentType = "image/jpg";

        //            break;

        //    }



        //    //Calculate size of file to be uploaded

        //    DateTime dt = DateTime.UtcNow.Date;
        //    DateTime dateTime = DateTime.UtcNow.Date;
        //    // Response.Write(dateTime.ToString("yyyy/M/dd"));
        //    string s_date = dateTime.ToString("yyyy/M/dd");


        //    //Calculate size of file to be uploaded

        //    int fileSize = FileUpload1.PostedFile.ContentLength;



        //    //Create array and read the file into it

        //    byte[] documentBinary = new byte[fileSize];

        //    FileUpload1.PostedFile.InputStream.Read(documentBinary, 0, fileSize);
        //    SqlConnection conn2 = null;
        //    conn2 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        //    conn2.Open();
        //    //  SqlCommand cmd1 = new SqlCommand("insert into task values(@action_,@c_id ,@added_by, @c_name,@to_do ,@created ,@updated,@agent,@sec_agent,@DocName,@Type_,@DocData,@rank_,@commission,@refer,@comment)", conn2);
        //    SqlCommand cmd1 = new SqlCommand("insert into task values(@action_,@c_id ,@added_by, @c_name,@to_do ,@created ,@updated,@fast_reminder,@agent,@sec_agent,@rank_,@commission,@refer,@comment,@DocName,@Type_,@DocData,@subject,@status,@category,@fullday)", conn2);

        //    cmd1.Parameters.AddWithValue("@action_", "0");
        //    cmd1.Parameters.AddWithValue("@c_id", DropDownList1.SelectedValue);
        //    cmd1.Parameters.AddWithValue("@added_by", Session["email"]);

        //    cmd1.Parameters.AddWithValue("@c_name", DropDownList3.SelectedValue);
        //    cmd1.Parameters.AddWithValue("@to_do", DropDownList4.SelectedValue);
        //    cmd1.Parameters.AddWithValue("@created", s_date.ToString());
        //    cmd1.Parameters.AddWithValue("@updated", txtupdate.Text);
        //    cmd1.Parameters.AddWithValue("@fast_reminder", txtreminder.Text);
        //    cmd1.Parameters.AddWithValue("@agent", txtagent.Text);
        //    cmd1.Parameters.AddWithValue("@sec_agent", DropDownList6.SelectedValue);
        //    cmd1.Parameters.AddWithValue("@rank_", txtrank.Text);
        //    cmd1.Parameters.AddWithValue("@commission", txtagent.Text);
        //    cmd1.Parameters.AddWithValue("@refer", TextBox2.Text);
        //    cmd1.Parameters.AddWithValue("@comment", txtcomment.Text);
        //    cmd1.Parameters.AddWithValue("@subject", DropDownList28.SelectedValue);
        //    cmd1.Parameters.AddWithValue("@status", DropDownList29.SelectedValue);
        //    cmd1.Parameters.AddWithValue("@category", txtcatname.Text);
        //    cmd1.Parameters.AddWithValue("@fullday", DropDownList30.SelectedValue);
        //    SqlParameter DocName = new SqlParameter("@DocName", SqlDbType.VarChar, 50);

        //    DocName.Value = fileName.ToString();

        //    cmd1.Parameters.Add(DocName);
        //    SqlParameter Type = new SqlParameter("@Type_", SqlDbType.VarChar, 50);

        //    Type.Value = documentType.ToString();

        //    cmd1.Parameters.Add(Type);



        //    SqlParameter uploadedDocument = new SqlParameter("@DocData", SqlDbType.Binary, fileSize);

        //    uploadedDocument.Value = documentBinary;

        //    cmd1.Parameters.Add(uploadedDocument);



        //    cmd1.ExecuteNonQuery();






















        //    SqlConnection conn4 = null;
        //    conn4 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        //    conn4.Open();

        //    SqlCommand cmd4 = new SqlCommand("INSERT INTO Tbl_Calendar(title, description, event_start, event_end) VALUES(@title, @description, @event_start, @event_end)", conn4);
        //    cmd4.Parameters.AddWithValue("@title", DropDownList4.SelectedValue);
        //    cmd4.Parameters.AddWithValue("@description", DropDownList6.SelectedValue);
        //    cmd4.Parameters.AddWithValue("@event_start", txtreminder.Text);
        //    cmd4.Parameters.AddWithValue("@event_end", System.DateTime.Now.ToString());
        //    cmd4.ExecuteNonQuery();
        //    Response.Redirect("Admin_Notes_conf.aspx");
        //    //Label1.Text = Session["email_id"].ToString();


        //}

    }

    protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        //        if (e.CommandName == "action")
        //        {

        //            //Label1.Text = "hello";
        //            int index = Convert.ToSByte(e.CommandArgument);

        //            GridViewRow row = gvUserInfo.Rows[index];
        //            SqlDataAdapter adp = new SqlDataAdapter();
        //            SqlCommand cmd1 = new SqlCommand();
        //            DataSet ds = new DataSet();


        //            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

        //            con.Open();

        //            SqlCommand objectvalue = new SqlCommand("", con);
        //            cmd1.Connection = con;



        //            SqlCommand dmc = new SqlCommand("insert into notes(c_id,f_name,notes,date_) values ('" + row.Cells[0].Text + "','" + row.Cells[1].Text + "','" + DropDownList5.SelectedValue + "','" + System.DateTime.Now + "')", con);

        //            dmc.ExecuteNonQuery();
        //            //cmd.Parameters.AddWithValue("@notes", DropDownList2.SelectedValue);

        //con.Close();

        //            Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");

        //            // con.Close();


        //        }
        //    }



    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        //        if (e.CommandName == "action")
        //        {

        //            //Label1.Text = "hello";
        //            int index = Convert.ToSByte(e.CommandArgument);

        //            GridViewRow row = gvUserInfo.Rows[index];
        //            SqlDataAdapter adp = new SqlDataAdapter();
        //            SqlCommand cmd1 = new SqlCommand();
        //            DataSet ds = new DataSet();


        //            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

        //            con.Open();

        //            SqlCommand objectvalue = new SqlCommand("", con);
        //            cmd1.Connection = con;



        //            SqlCommand dmc = new SqlCommand("insert into notes(c_id,f_name,notes,date_) values ('" + row.Cells[0].Text + "','" + row.Cells[1].Text + "','" + DropDownList5.SelectedValue + "','" + System.DateTime.Now + "')", con);

        //            dmc.ExecuteNonQuery();
        //            //cmd.Parameters.AddWithValue("@notes", DropDownList2.SelectedValue);

        //con.Close();

        //            Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");

        //            // con.Close();


        //        }
        //    }



    }
    protected void LinkButton1_Click(object sender, System.EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("../admin.aspx");
    }


}